<template>
	<view class="app-container">
		<view class="con-padding">
			<view class="head">
				<view class="top">
					<text>等级：v{{userInfo.vpnLevel}}</text>
					<view class="notice" @click="handelMsg">
						<u-icon class="icon-bell" name="bell-fill" size="24px" color="#fff"></u-icon>
						<u-badge showZero absolute :offset="[-2,-10]" numberType="overflow" max="99" type="error" :value="msg">
						</u-badge>
					</view>
				</view>
				<view class="bottom">
					<text>今日：{{ formatNum(userInfo.activateCount) }}</text>
				</view>
			</view>
			<view class="balance">
				<u-grid :border="false" @click="handleGO">
					<u-grid-item v-for="(item,index) in baseList" :key="index" :name="item.url">
						<u--image :src="item.name" width="24px" height="24px"></u--image>
						<text class="grid-text">{{item.title}}</text>
					</u-grid-item>
				</u-grid>
			</view>
		</view>
		<view class="setting">
			<u-cell-group :border="false">
				<u-cell isLink url="../income/income">
					<u-icon slot="icon" size="22" name="rmb-circle" color="#5fe5ed"></u-icon>
					<view slot="title" class="u-slot-title">
						<text class="u-cell-text">收益明细</text>
					</view>
				</u-cell>
				<u-cell isLink url="../auth/auth">
					<u-icon slot="icon" size="22" name="../../static/my_icon/auth.png"></u-icon>
					<view slot="title" class="u-slot-title">
						<text class="u-cell-text">实名认证</text>
					</view>
					<view slot="value">
						<u-tag :text="userInfo.isAuth ? '已认证' : '未认证'" plain size="mini"
							:type="userInfo.isAuth ? 'success' : 'error'">
						</u-tag>
					</view>
				</u-cell>
				<u-cell isLink url="../personal/personal">
					<u-icon slot="icon" size="22" name="setting" color="#5fe5ed"></u-icon>
					<view slot="title" class="u-slot-title">
						<text class="u-cell-text">个人信息</text>
					</view>
				</u-cell>
				<u-cell isLink url="../userAgree/userAgree">
					<u-icon slot="icon" size="22" name="../../static/my_icon/container.png" color="#5fe5ed"></u-icon>
					<view slot="title" class="u-slot-title">
						<text class="u-cell-text">用户协议</text>
					</view>
				</u-cell>
				<u-cell isLink url="../privacy/privacy">
					<u-icon slot="icon" size="22" name="../../static/my_icon/layout.png" color="#5fe5ed"></u-icon>
					<view slot="title" class="u-slot-title">
						<text class="u-cell-text">隐私协议</text>
					</view>
				</u-cell>
				<u-cell isLink url="../about/about">
					<u-icon slot="icon" size="22" name="info-circle" color="#5fe5ed"></u-icon>
					<view slot="title" class="u-slot-title">
						<text class="u-cell-text">关于星屺</text>
					</view>
					<view slot="value" class="u-slot-value">
						<text>Version {{ version }}</text>
						<u-badge v-if="newVersion" :isDot="true" type="error" class="badge"></u-badge>
					</view>
				</u-cell>
				<u-cell @click="logout" :border="false" isLink>
					<u-icon slot="icon" size="20" name="../../static/my_icon/logout.png" color="#5fe5ed"></u-icon>
					<view slot="title" class="u-slot-title">
						<text class="u-cell-text">退出登录</text>
					</view>
				</u-cell>
			</u-cell-group>
		</view>
	</view>
</template>

<script>
	import {
		getInfo,
		getPersonageInfo
	} from "@/api/user.js"
	export default {
		data() {
			return {
				baseList: [{
						name: require('../../static/my_icon/Dollar.png'),
						title: '提现',
						url: "../withdrawal/withdrawal"
					},
					{
						name: require('../../static/my_icon/CI.png'),
						title: '账户余额',
						url: "../balance/balance"
					},
					{
						name: require('../../static/my_icon/meh.png'),
						title: '活跃度余额',
						url: "../balance/activity"
					},
				],
				haveNotice: false,
				version: "1.0.1",
				newVersion: false,
				userInfo: {},
				msg: 3,
			}
		},
		onShow() {
			this.getInfo();
			this.msg = uni.getStorageSync("message");
			this.version = uni.getStorageSync("version")
			this.newVersion = uni.getStorageSync("isNew")
		},
		methods: {
			handleGO(name) {
				uni.navigateTo({
					url: name,
					fail: (res) => {
						console.log(res);
					}
				})
			},
			logout() {
				let _this = this
				uni.showModal({
					title: '',
					content: '是否确认退出',
					confirmText: "确认",
					success: function(res) {
						if (res.confirm) {
							_this.$store.dispatch("user/logout");
						} else if (res.cancel) {
							// console.log('用户点击取消');
						}
					}
				});
			},
			getInfo() {
				this.$store.dispatch('user/getInfo').then(res => {
					console.log(res);
					let {
						vpnLevel,
						activateCount,
						isAuth
					} = res
					this.userInfo = {
						vpnLevel,
						activateCount,
						isAuth
					}
				});
			},
			formatNum(num) {
				return Number(num).toFixed(2).toLocaleString()
			},
			handelMsg() {
				uni.navigateTo({
					url: "../message/message",
					fail: (res) => {
						console.log(res);
					}
				})
			},
		}
	}
</script>

<style lang="scss">
	page {
		// background-color: #031335;
		background: url("@/static/image/12.jpg") no-repeat;
		background-size: 100% 100%;
	}

	.app-container {
		padding: 40px 0px;

		.con-padding {
			padding: 0px 20px;
		}
	}

	.head {
		width: 100%;
		height: 100px;
		border-radius: 4px;
		// background: linear-gradient(to right, rgba(48, 48, 48, 0.8), rgba(0, 0, 0, 0.9));
		background: url("@/static/image/rc.png") no-repeat;
		background-size: 100% 100%;
		color: #fff;
		padding: 15px 20px;
		display: flex;
		flex-direction: column;
		justify-content: space-between;
		// outline: 1px solid red;

		.top {
			display: flex;
			align-items: center;
			justify-content: space-between;

			.notice {
				display: flex;
				position: relative;

				.icon-bell {
					margin-right: 6px;
				}
			}
		}
	}

	.balance {
		margin-top: 10px;
		padding: 20px 0;
		// background-color: #fff;
		color: #fff;
		border-radius: 8px;
		background: url("@/static/image/R-C.jpg") no-repeat;
		background-size: 100% 100%;

		.grid-text {
			margin-bottom: 5px;
		}
	}

	.setting {
		margin-top: 20px;
		color: #5fe5ed;
		padding: 0 10px;

		.u-cell-text,
		.u-slot-value {
			color: #5fe5ed;
		}

		/deep/ .u-icon__icon--info {
			color: #5fe5ed;
		}
	}

	.u-slot-value {
		display: flex;
		align-items: center;

		.badge {
			margin-left: 5px;
		}
	}
</style>
